package spindles.gwt.server.util;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import spindles.api.db.DB;
import spindles.api.services.MatlabGateway;
import spindles.api.util.Config;
import spindles.gwt.server.ServletUtil;

/**
 * A ServletContextListener that handles
 * initialization tasks when the web application starts.
 *
 */
public class ApplicationListener implements ServletContextListener {
	
    // Notification that the web application is ready to process requests
    public void contextInitialized(ServletContextEvent sce) {    	
    	Config.init(sce.getServletContext().getRealPath("/WEB-INF/"));
    	ServletUtil.init(sce.getServletContext());
    } 

    

    // Notification that the servlet context is about to be shut down
    public void contextDestroyed(ServletContextEvent sce) {
    	MatlabGateway.dispose();
    	DB.close();   	
    }
}